package com.ljh.controller;


import com.ljh.common.JsonData;
import com.ljh.pojo.Client;
import com.ljh.pojo.OutTable;
import com.ljh.service.CLIENTervice;
import com.ljh.service.DINDINGervice;
import com.ljh.service.OUTTABLEervice;
import com.ljh.vo.OutTableVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 刘剑鸿
 * @since 2021-10-29
 */
@Controller
@RequestMapping("/outTable")
public class OutTableController {

    @Autowired
    private OUTTABLEervice outtablEervice;
    @Autowired
    private CLIENTervice clienTervice;
    @Autowired
    private DINDINGervice dindinGervice;

    /*查询已开台表格*/
    @RequestMapping("toOutTable")
    @ResponseBody
    public JsonData toOutTable(OutTableVo outTableVo){
        return outtablEervice.selectOutTable(outTableVo);
    }

    /*新增开台*/
    @RequestMapping("addOuttable")
    public String addOuttable(Client client,OutTable outTable){

        try {
            if (client.getClientid() == 0){
                clienTervice.addClient(client);
            }
            //会员客户 不用新增
            int clientId = client.getClientid();
            int dining = outTable.getDiningTableid();
            System.out.println(dining);
            dindinGervice.updateOutTable(dining);

            outTable.setClientid(clientId);
            outtablEervice.addOut(outTable);
            //return JsonData.success("用户添加成功");
//            int dindingId = ;

            return "redirect:/user/index";
        }
        catch (Exception e){
            return "";
        }

    }
}

